<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>深拷贝</title>
</head>
<body>
    <script>
        const obj1 = {
            age:10,
            cars:['maibahe','binli','benchi'],
            sex:'man',
            feture:{
                fav:'run',
                eat:'vegetables'
            }
            
        }

        function extend(obj1,obj2) {
            for( let key in obj1) {
                let item = obj1[key]
                // if(typeof item === 'object') {
                //     let val = obj2[key]
                //     extend(item,val)
                // }else {
                //     obj2[key] = item
                // }
                if(item instanceof Array) {
                    obj2[key] = []
                    extend(item,obj2[key])
                }else if(item instanceof Object) {
                    obj2[key] = {}
                    extend(item,obj2[key])
                }else {
                    obj2[key] = obj1[key]
                }
            }
        }
        const obj2 = {}
        extend(obj1,obj2)
        console.log(obj2)
    </script>
</body>
</html>